package com.xyhuo.leetcode.y2025;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MajorityElement {

    public List<Integer> majorityElement(int[] nums) {
        List<Integer> ans = new ArrayList<>();
        Map<Integer, Long> map = Arrays.stream(nums)
                .boxed()
                .collect(Collectors.groupingBy(num -> num, Collectors.counting()));
        float count = ((float) nums.length) / 3;
        for (Map.Entry<Integer, Long> entry : map.entrySet()) {
            if (entry.getValue() > count) {
                ans.add(entry.getKey());
            }
        }
        return ans;
    }
}
